<template>
  <base-breadcrumb :breadcrumb="!isAudit">
    <template v-slot:content>
      <a-card
        :body-style="{ padding: '24px 32px' }"
        :bordered="false"
      >
        <title-name title="双优化立项信息" />
        <baseInfo :form="dels"></baseInfo>
      </a-card>

<!--      <a-card-->
<!--        :body-style="{ padding: '24px 32px' }"-->
<!--        style="margin-top: 20px"-->
<!--        :bordered="false"-->
<!--      >-->
<!--        <title-name-->
<!--          v-if="dels.statusCode != 0"-->
<!--          title="双优化销项信息"-->
<!--        />-->
<!--        <a-form-model-->
<!--          v-if="dels.statusCode != 0"-->
<!--          ref="form1"-->
<!--          layout="horizontal"-->
<!--          :model="form"-->
<!--          :rules="rules"-->
<!--        >-->
<!--          <a-row :gutter="24">-->
<!--            <a-col-->
<!--              :md="8"-->
<!--              :sm="8"-->
<!--            >-->
<!--              <a-form-model-item-->
<!--                label="实施情况"-->
<!--                :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"-->
<!--                :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"-->
<!--                prop="branchId"-->
<!--              >-->
<!--                <BaseInput-->
<!--                  v-model="dels.isImpl"-->
<!--                  type="text"-->
<!--                  disabled-->
<!--                />-->
<!--              </a-form-model-item>-->
<!--            </a-col>-->
<!--            <a-col-->
<!--              :md="8"-->
<!--              :sm="8"-->
<!--            >-->
<!--              <a-form-model-item-->
<!--                label="销项人"-->
<!--                :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"-->
<!--                :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"-->
<!--                prop="projectId"-->
<!--              >-->
<!--                <BaseInput-->
<!--                  v-model="dels.sellerName"-->
<!--                  placeholder=""-->
<!--                  disabled-->
<!--                />-->
<!--              </a-form-model-item>-->
<!--            </a-col>-->
<!--            <a-col-->
<!--              :md="8"-->
<!--              :sm="8"-->
<!--            >-->
<!--              <a-form-model-item-->
<!--                label="销项时间"-->
<!--                :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"-->
<!--                :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"-->
<!--              >-->
<!--                <BaseInput-->
<!--                  v-model="dels.salesTime"-->
<!--                  placeholder=""-->
<!--                  disabled-->
<!--                />-->
<!--              </a-form-model-item>-->
<!--            </a-col>-->
<!--          </a-row>-->

<!--          <a-row :gutter="24">-->
<!--            <a-col-->
<!--              :md="24"-->
<!--              :sm="24"-->
<!--            >-->
<!--              <a-form-model-item-->
<!--                label="备注信息"-->
<!--                :label-col="{ lg: { span: 2 }, sm: { span: 2 } }"-->
<!--                :wrapper-col="{ lg: { span: 22 }, sm: { span: 22 } }"-->
<!--              >-->
<!--                <BaseTextarea-->
<!--                  v-model="dels.remarks"-->
<!--                  :disabled="true"-->
<!--                />-->
<!--              </a-form-model-item>-->
<!--            </a-col>-->
<!--          </a-row>-->
<!--        </a-form-model>-->
<!--        <title-name-->
<!--          v-if="dels.statusCode != 0"-->
<!--          title="上传相关附件"-->
<!--        />-->
<!--        <u-table-->
<!--          v-if="dels.statusCode != 0"-->
<!--          :list-url="listUrl"-->
<!--          :is-show="false"-->
<!--          :delete-url="deleteUrl"-->
<!--          :upload-arrys="uploadArrys"-->
<!--          :upload-list="uploadList"-->
<!--          business-code="PM18"-->
<!--        />-->
<!--      </a-card>-->

      <a-card
        :body-style="{ padding: '24px 32px' }"
        style="margin-top: 20px"
        :bordered="false"
      >
        <title-name
          v-if="dels.statusCode == 3 || dels.statusCode == 4"
          title="双优化验收信息"
        />
        <a-form-model
          v-if="dels.statusCode == 3 || dels.statusCode == 4"
          layout="horizontal"
        >
          <a-row :gutter="24">
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="实际完成时间"
                :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                prop="branchId"
              >
                <BaseInput
                  v-model="dels.completeTime"
                  type="text"
                  disabled
                />
              </a-form-model-item>
            </a-col>
            <a-col
              :md="16"
              :sm="16"
            >
              <a-form-model-item
                label="主要实施人员"
                :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                prop="projectId"
              >
                <BaseInput
                  v-model="dels.mainImplsName"
                  placeholder=""
                  disabled
                />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row :gutter="24">
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="实际减亏效益"
                :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
              >
                <BaseInput
                  v-model="dels.actualReduceBenefit"
                  placeholder=""
                  disabled
                />
              </a-form-model-item>
            </a-col>
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="实际增加效益"
                :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
                prop="projectId"
              >
                <BaseInput
                  v-model="dels.actualIncreaseBenefit"
                  placeholder=""
                  disabled
                />
              </a-form-model-item>
            </a-col>
            <a-col
              :md="8"
              :sm="8"
            >
              <a-form-model-item
                label="实际效益"
                :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
              >
                <BaseInput
                  v-model="dels.actualBenefit"
                  placeholder=""
                  disabled
                />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row :gutter="24">
            <a-col
              :md="24"
              :sm="24"
            >
              <a-form-model-item
                label="验收概述"
                :label-col="{ lg: { span: 7 }, sm: { span: 7 } }"
                :wrapper-col="{ lg: { span: 17 }, sm: { span: 17 } }"
              >
                <editor
                  v-model="dels.acceptance"
                  disabled
                />
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
        <title-name
          v-if="dels.statusCode == 3 || dels.statusCode == 4"
          title="上传相关附件"
        />
        <u-table
          v-if="dels.statusCode == 3 || dels.statusCode == 4"
          :list-url="listUrl"
          :is-show="false"
          :delete-url="deleteUrl"
          :upload-arrys="uploadArrys1"
          :upload-list="uploadList"
          business-code="PM18"
        />
      </a-card>

      <div v-if="!isConsultation" class="page-btn-right-top">
        <a-button
          type="primary"
          @click="goBack"
        >
          关闭
        </a-button>
      </div>
    </template>
  </base-breadcrumb>
</template>

<script>
import { getImplementationDetails } from '@/api/project/implementation'
import baseInfo from "./components/baseInfo"

const columns = [
    {
        title: '序号',
        width: 65,
        dataIndex: 'serial',

        scopedSlots: { customRender: 'serial' }
    },
    {
        title: '设计资源名称',
        dataIndex: 'name',
        width: '20%'
    },
    {
        title: '设计资源类型',
        dataIndex: 'type',
        width: '30%'
    },
    {
        title: '设计资源等级',
        dataIndex: 'level',
        width: '30%'
    }
]

const columnAssment = [
    {
        title: '序号',
        width: 65,
        dataIndex: 'serial',

        scopedSlots: { customRender: 'serial' }
    },
    {
        title: '附件名称',
        dataIndex: 'name',
        width: '15%'
    },
    {
        title: '附件格式',
        dataIndex: 'format',
        width: '15%'
    },
    {
        title: '附件地址',
        dataIndex: 'address',
        width: '40%'
    },
    {
        title: '操作',
        key: 'action',
        width: '20%',
        scopedSlots: { customRender: 'action' }
    }
]
export default {
    name: 'a' + Date.now(),
    components: {
        baseInfo
    },
    props: {
      // 是否作为审批详情
      isAudit: {
        type: Boolean,
        default: false
      },
      // 是否作为意见征询
      isConsultation: {
        type: Boolean,
        default: false
      }
    },
    data() {
        return {
            columns,
            columnAssment,

            // 附件上传
            listUrl: '',
            deleteUrl: '/cscec-project-business/file/business/project-fileDelete',
            uploadList: '/cscec-project-business/file/business/fileUpload',

            mainImplementers: [],
            data: [],
            dels: {
              viewName: ""
            },
            dataSource: [
                { name: '', type: '设计单位', level: '' },
                { name: '', type: '设计专家', level: '' },
                { name: '', type: '海外设计单位', level: '' },
                { name: '', type: '海外设计专家', level: '' }
            ],

            visible: false,
            title: '选择设计资源',

            form: {},
            form2: {
                actualBenefit: '',
                actualReduceBenefit: '',
                actualIncreaseBenefit: ''
            },
            currentDate: '', // 当前日期

            selectedRowKeys: [],
            selectedRows: [],

            isEdit: '',
            id: '',

            uploadArrys: [],
            uploadArrys1: [],

            companys: [],
            projectNames: [],
            projectType: '',
            type: '',

            rules: {
                completeTime: [{ required: true, message: '请选择实际完成时间', trigger: 'blur' }],
                implementers: [{ required: true, message: '请选择主要实施人员', trigger: 'blur' }],
                actualReduceBenefit: [{ required: true, message: '请输入实际减亏效益', trigger: 'blur' }],
                actualIncreaseBenefit: [{ required: true, message: '请输入实际增加效益', trigger: 'blur' }],
                actualBenefit: [{ required: true, message: '请输入实际效益', trigger: 'blur' }],
                acceptance: [{ required: true, message: '请输入验收概述', trigger: 'blur' }]
            }
        }
    },

    created() {
        this.id = this.$route.query.id
        this.type = this.$route.query.type

        this.getOptimizationDetails()
    },
    computed: {
        rowSelection() {
            return {
                selectedRowKeys: this.selectedRowKeys,
                selectedRows: this.selectedRows, // 当前行所有数据
                onChange: this.onSelectChange
            }
        }
    },
    methods: {
        getOptimizationDetails() {
            let that = this
            if (that.type == 'approve' || this.isAudit) {
                that.id = that.id.replace(/[^0-9]/gi, '')
            }
            getImplementationDetails({ id: that.id }).then((res) => {
                that.dels = res.data
               this.dels.viewName =  this.dels.branch +"/"+ this.dels.projectName

                if (that.dels.typeId == 111) {
                    that.dels.typeName = '设计优化'
                } else if (that.dels.typeId == 222) {
                    that.dels.typeName = '施工组织设计(方案)优化'
                }
                that.dels.forecastBenefit = parseFloat(
                    parseFloat(that.dels.increaseBenefit) + parseFloat(that.dels.reduceBenefit)
                ).toFixed(2)
                // implementFileIdsInfo

                // let names = res.data.mainImplementers
                // let nameArr = []
                // names.forEach(function(obj,i) {
                //   nameArr.push(obj.name)
                // })
                // that.dels.mainImplementers = nameArr.join(",")

                that.dels.actualBenefit = parseFloat(
                    parseFloat(that.dels.actualIncreaseBenefit) + parseFloat(that.dels.actualReduceBenefit)
                ).toFixed(2)
                that.uploadArrys = that.dels.outputFileIdsInfo
                that.uploadArrys1 = that.dels.implementFileIdsInfo
            })
        },

        goBack() {
            if (this.type == 'approve') {
                window.close()
            } else {
                this.$multiTab.close(this.$route.fullpath)
            }
        }
    }
}
</script>
